//
//  Extension+String.swift
//  MevosSwift
//
//  Created by roy on 2017/4/19.
//  Copyright © 2017年 roy. All rights reserved.
//

import UIKit

extension String {
    func toolsChangeToJson(info: Any) -> String{
        //首先判断能不能转换
        guard JSONSerialization.isValidJSONObject(info) else {
            print("json转换失败")
            return ""
        }
        //如果设置options为JSONSerialization.WritingOptions.prettyPrinted，则打印格式更好阅读
        let jsonData = try? JSONSerialization.data(withJSONObject: info, options: [])
        
        if let jsonData = jsonData {
            let str = String(data: jsonData, encoding: String.Encoding.utf8)
            return str ?? ""
        }else {
            return ""
        }
    }

}
